﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace ClientAppraise.Converters
{
    public class IntToEnumConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length != 2) return "";

            if (values[0] is not int enumValue)
            {
                return "";
            }

            if (values[1] is not Type type|| !type.IsEnum)
            {
                return "";
            }

            if (!Enum.TryParse(type, enumValue.ToString(), out object? result)) {
                return "";
            }
            //先这么写吧，按理这里最好取描述信息，如果没有时再取名称，，但先这样吧

            return result!.ToString()!;
        }

        public object[] ConvertBack(
            object value,
            Type[] targetTypes,
            object parameter,
            CultureInfo culture
        )
        {
            throw new NotImplementedException();
        }
    }
}
